using System;
using System.Collections.Generic;
using aprogblog.Domain;
using aprogblog.Domain.Helpers;

namespace aprogblog.App.MetaWeblog {

    public static class EntryConverters {
        
        public static Entry ToEntry(this Post Post) { return new Entry {
            Id = (Post.postid ?? Guid.NewGuid()).ToString(),
            Title = Post.title,
            Description = Post.description
        };}
        
        public static Post ToPost(this Entry Entry) { return new Post {
            postid = Entry.Id,
            title = Entry.Title,
            description = Entry.Description
        };}
        
        public static List<Entry> ToEntries(this Post[] Posts) {
            var Entries = new List<Entry>();
            Posts.ForEach(Post => Entries.Add(Post.ToEntry()));
            return Entries;
        }
        
        public static Post[] ToPosts(this List<Entry> Entries) {
            var Posts = new Post[Entries.Count];

            for (var i = 0; i < Entries.Count; i++)
                Posts[i] = Entries[i].ToPost();

            return Posts;
        }
    }
}